package com.jiyici.utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import android.os.Environment;

public class FileLogger {
	
	
	
	
	final static String FileD = Environment.getExternalStorageDirectory()+"/postcard.log";
	static FileLogger mInstance;
	BufferedWriter bw;
	FileWriter fw ;
	public static FileLogger getInstance()
	{
		if(mInstance == null)
			mInstance =new FileLogger();
		
		return mInstance;
	}
	
	public void init()
	{
		File test = new File(FileD);
		if(test.exists())
			test.delete();
		
		
		try {
			fw = new FileWriter(FileD);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		bw=new BufferedWriter(fw);
		
		
	}
	
	public void Log(String msg)
	{
		try {
			bw.write(msg+"\n");
			bw.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void release()
	{
		if(fw != null)
		{
			try {
				fw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		if(bw!= null)
		{
			try {
				bw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
	}

}
